#include <IRremote.h>
int RECV_PIN = 11;
int ledPin = 10;
boolean ledState = LOW;  //ledstate用来储存LED状态
IRrecv irrecv(RECV_PIN);
//设置RECV_PIN（也就是引脚11）为红外接收端
//decode_results results;  //旧版：2.6.0 定义results变量为红外结果存放位置

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  irrecv.enableIRIn();
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  //是否收到解码数据，把接收到的数据存储在变量results中
  if (irrecv.decode()) {  //旧版：irrecv.decode(&results)
    //接收到的数据以16进制方式在串口输出
    Serial.println(irrecv.decodedIRData.decodedRawData, HEX);

    //一旦接收到电源键的代码，LED翻转状态，HIGH变LOW，或者LOW变HIGH
    if (irrecv.decodedIRData.decodedRawData == 0xF30CFF00) {
      ledState = !ledState;
      digitalWrite(ledPin, ledState);
    }
    irrecv.resume();
  }
}
